package com.it.controller;


import com.it.common.Result;
import com.it.domain.Banner;
import com.it.service.BannerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RequestMapping("/banner")
@RestController
public class BannerController {

    @Autowired
    private BannerService bannerService;


    @PostMapping("/AddBanner")
    public Result AddBanner(@RequestBody Banner banner){
        return (Result) bannerService.AddBanner(banner);
    }

    @GetMapping("/SelectBanner")
    public List<Banner> SelectBanner(Banner banner){
        List<Banner> banners = bannerService.SelectBanner(banner);
        if(banners.size() == 0){
            return null;
        }
        else{
            return banners;
        }
    }

    @PutMapping("/SetBannerType")
    public Result SetBannerType(@RequestBody Banner banner){
        return bannerService.SetBannerType(banner);
    }

    @GetMapping("/getAllBanner")
    public List<Banner> getAllBanner(){
        List<Banner> banners = bannerService.getAllBanner();
        if(banners.size() == 0){
            return null;
        }
        else {
            return banners;
        }
    }

    @GetMapping("/getBannerPosition/{id}")
    public List<Banner> getBannerPosition(@PathVariable Integer id){
        return bannerService.getBannerPosition(id);
    }


    @DeleteMapping("/DeleteBanner/{id}")
    public Result DeleteBanner(@PathVariable Integer id){
        if(bannerService.DeleteBanner(id)>0){
            return Result.success("200","删除成功");
        }
        else {
            return Result.fail("490","删除失败");
        }
    }
}
